import request from '@/utils/request';
import {
	SubmitOrderResponseData,
	OrderInfoResponseData,
	ResponseData,
	PayInfoResponseData,
	UserInfoResponseData,
	CertificatesTypeResponseData,
	UserCertationParams,
	OrderListResponseData,
	OrderStateResponseData,
	CityResponseData,
	SubmitPatientData,
	GetPatientByIdResponseData,
} from './type';

enum API {
	// 提交订单，获取订单号码接口
	SUBMITORDER = '/order/orderInfo/auth/submitOrder/',
	// 获取订单详情的数据
	GETORDERINFO = '/order/orderInfo/auth/getOrderInfo/',
	// 取消订单的接口
	ORDERCANCEL = '/order/orderInfo/auth/cancelOrder/',
	// 获取支付订单二维码接口
	QRCODE = '/order/weixin/createNative/',
	// 查询订单支付的结果
	PAYRESULT = '/order/weixin/queryPayStatus/',
	// 获取当前账号用户信息
	GETUSERINFO = '/user/auth/getUserInfo',
	// 获取证件的类型的接口地址
	CERTIFICATIONTYPE = '/cmn/dict/findByDictCode/',
	// 用户认证的接口
	USERCERTATION = '/user/auth/userAuah',
	// 获取用户订单号的数据
	USERORDERINFO = '/order/orderInfo/auth/',
	// 获取订单的状态
	ORDERSTATE = '/order/orderInfo/auth/getStatusList',
	// 获取城市的数据
	CITY = '/cmn/dict/findByParentId/',
	// 新增就诊人信息
	ADDPATIENT = '/user/patient/auth/save',
	// 修改就诊人信息
	UPDATEPATIENT = '/user/patient/auth/update',
	// 根据id获取就诊人
	GETPATIENTBYID = '/user/patient/auth/get/',
	// 根据id删除就诊人
	DELETEPATIENTBYID = '/user/patient/auth/remove/',
}

// 提交订单
export function submitOrder(hoscode: string, scheduleId: string, patientId: number) {
	return request.post<any, SubmitOrderResponseData>(API.SUBMITORDER + `${hoscode}/${scheduleId}/${patientId}`);
}

export function getOrderInfo(orderId: number) {
	return request.get<any, OrderInfoResponseData>(API.GETORDERINFO + orderId);
}

export function orderCancel(orderId: number) {
	return request.get<any, ResponseData>(API.ORDERCANCEL + orderId);
}

export function getQrcode(orderId: number) {
	return request.get<any, PayInfoResponseData>(API.QRCODE + orderId);
}

export function payResult(orderId: number) {
	return request.get<any, ResponseData>(API.PAYRESULT + orderId);
}

export function getUserInfo() {
	return request.get<any, UserInfoResponseData>(API.GETUSERINFO);
}

export function getCertationType(type = 'certificatesType') {
	return request.get<any, CertificatesTypeResponseData>(API.CERTIFICATIONTYPE + type);
}

export function userCertation(data: UserCertationParams) {
	return request.post<any, ResponseData>(API.USERCERTATION, data);
}

export function getUserOrderInfo(page: number, limit: number, patientId?: number, orderStatus?: string) {
	return request.get<any, OrderListResponseData>(API.USERORDERINFO + `${page}/${limit}`, {
		params: {
			patientId,
			orderStatus,
		},
	});
}

export function getOrderState() {
	return request.get<any, OrderStateResponseData>(API.ORDERSTATE);
}

export function getCity(parentId: string) {
	return request.get<any, CityResponseData>(API.CITY + parentId);
}

export function addAndupdatePatient(data: SubmitPatientData) {
	if (data.id) {
		return request.put<any, ResponseData>(API.UPDATEPATIENT, data);
	} else {
		return request.post<any, ResponseData>(API.ADDPATIENT, data);
	}
}

export function getPatientById(id: number) {
	return request.get<any, GetPatientByIdResponseData>(API.GETPATIENTBYID + id);
}

export function deletePatientById(id: number) {
	return request.delete<any, ResponseData>(API.DELETEPATIENTBYID + id);
}
